home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
TERMINAL
/
1589.ZIP
/
TERMINIT.C
< prev
next >
Wrap
Text File
|
1989-04-13
|
8KB
|
228 lines
/* TempINIT.c - Initialization portion of application */
#include "windows.h"
#include "icu_user.h"
#include "term.h"
int FAR TermInit( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
HANDLE hInstance, hPrevInstance;
LPSTR lpszCmdLine;
int cmdShow;
{
int i;
long l;
char ch;
HANDLE hSysMenu;
if ( hPrevInstance == 0 ) { /* No other terminal is running */
if ( TermInitInstance(hInstance) == FALSE )
return( FALSE );
}
else { /* Copy global instance variables from previous instance */
GetInstanceData(hPrevInstance, (PSTR)szAppName, 10);
GetInstanceData(hPrevInstance, (PSTR)&hbrWhite, sizeof(hbrWhite));
GetInstanceData(hPrevInstance, (PSTR)&hAccelTable,sizeof(hAccelTable));
}
unlink( "bug" );
/****************************************/
/* Allocate memory for the display */
/****************************************/
for ( i = 0, ch = ' ', no_lines = 24, no_cols = 80; i < no_lines+2; i++ ) {
display[i].Handle = LocalAlloc(LMEM_MOVEABLE, no_cols+4 );
display[i].string = LocalLock( display[i].Handle );
if ( display[i].Handle == NULL || display[i].string == NULL ) {
fileput("Unable to %s memory for display.",
(display[i].Handle==NULL?"allocate":"lock"));
return( FALSE );
}
if ( i >= no_lines ) ch = 'X' ; /* Signals error lines */
memset( display[i].string, ch, no_cols ); /* Fill memory with spaces */
memset( display[i].string+no_cols, '\0', 2 ); /* Terminate line */
}
/*********************************************
* read the winsize file for Height and Width *
*********************************************/
win_sz.size.left = width = CW_USEDEFAULT;
win_sz.size.right = height = 0;
LoadString( hInstance, IDSWINDOWNAME, (PSTR) win_sz.app_name, 30 );
ret = ReadWindowSize(&win_sz);
if (!ret) { /* old cord. were found */
width = win_sz.size.right - win_sz.size.left;
height = win_sz.size.bottom - win_sz.size.top;
if (win_sz.icon) /* window should be iconic */
cmdShow = SW_SHOWMINIMIZED;
}
/* Create a window instance of class "Terminal" */
LoadString(hInstance, IDSMAINTITLE, (LPSTR)buff, 100);
hWndTerm = CreateWindow(
(LPSTR)szAppName, /* window class name */
(LPSTR)buff, /* name appearing in window caption */
WS_TILEDWINDOW, /* Style, | WS_HSCROLL | WS_VSCROLL for scrollbar */
win_sz.size.left, /* x position */
win_sz.size.top, /* y position */
width, /* width */
height, /* height */
(HWND)NULL, /* parent window */
(HMENU)NULL, /* menu, or child window id */
(HANDLE)hInstance,/* handle to window instance */
(LPSTR)NULL /* params to pass on */
);
/****************************************
* modify the system menu *
****************************************/
hSysMenu = GetSystemMenu(hWndTerm,FALSE);
ChangeMenu(hSysMenu,0,NULL,NULL,MF_APPEND|MF_SEPARATOR);
ChangeMenu(hSysMenu,0,"Save Window Size",IDMSAVEWINDOW,MF_APPEND|MF_STRING);
/* Load the default configuration filename */
LoadString( hInstTerm, IDSCONFIGPATH, (PSTR) ConfigPath, 30 );
/* Modify main menu */
hMenuMain = GetMenu( hWndTerm );
EnableMenuItem( hMenuMain, 1, MF_BYPOSITION|MF_DISABLED|MF_GRAYED );
CheckMenuItem( GetSubMenu( hMenuMain, 1 ), IDMOFF, MF_CHECKED );
/* Setup the Dialog Procs. */
lpprocTimer = MakeProcInstance((FARPROC)Timer, hInstance);
lpprocDescDlg = MakeProcInstance((FARPROC)DescDlg, hInstance);
lpprocSelectDlg = MakeProcInstance((FARPROC)SelectDlg, hInstance);
lpprocConfigTerm = MakeProcInstance((FARPROC)ConfigTerm, hInstance);
lpprocTermAboutDlg = MakeProcInstance((FARPROC)TermAboutDlg, hInstance);
/* Make window visible */
ShowWindow(hWndTerm, cmdShow);
hWdesc = CreateDialog(hInstance,MAKEINTRESOURCE(DESCBOX),hWndTerm,lpprocDescDlg);
if ( hWdesc == FALSE ) /* Was the Dialog Box created? */
return(FALSE);
return TRUE; /* End if terminit(), return TRUE */
}
/*****************************************************************************/
/*****************************************************************************/
/* Procedure called when the application is loaded */
int TermInitInstance(hInstance)
HANDLE hInstance;
{
HANDLE hClass;
PWNDCLASS pTermClass;
/* set up default brush */
hbrWhite = GetStockObject(WHITE_BRUSH);
/* load Application string from resource */
LoadString(hInstance, IDSAPPNAME, (LPSTR)szAppName, 20);
/* Allocate class structure in local heap */
hClass = LocalAlloc( LMEM_MOVEABLE, sizeof(WNDCLASS));
pTermClass = (PWNDCLASS) LocalLock( hClass );
/* Get necessary resources */
pTermClass->hCursor = LoadCursor( NULL, IDC_ARROW );
pTermClass->hIcon = LoadIcon(hInstance, (LPSTR)szAppName);
pTermClass->lpszMenuName = (LPSTR)szAppName;
pTermClass->lpszClassName = (LPSTR)szAppName;
pTermClass->hbrBackground = hbrWhite;
pTermClass->hInstance = hInstance;
pTermClass->style = CS_VREDRAW | CS_HREDRAW;
/* Register our Window Proc */
pTermClass->lpfnWndProc = TermWndProc;
/* register this new class with WINDOWS */
if (!RegisterClass((LPWNDCLASS)pTermClass))
return FALSE; /* Initialization failed */
LocalUnlock( hClass );
LocalFree( hClass );
hAccelTable = LoadAccelerators(hInstance, (LPSTR)szAppName);
return TRUE; /* Initialization succeeded */
}
/*****************************************************************************/
/*****************************************************************************/
int TermOpenComm()
{
char buffer[80];
if ( nCID ) { /* A Comm port is active, close it */
CloseComm( nCID );
LocalUnlock( hCommHandle );
LocalFree( hCommHandle );
}
nCID = OpenComm((LPSTR) port_name, IN_QUEUE, OUT_QUEUE );
if ( nCID < 1 ) {
sprintf( buffer,"TermOpenComm(): OpenComm() error, status = %d", nCID );
pmsg( buffer );
return( FALSE );
}
/* Get memory for DCB structure and lock it while port is open */
hCommHandle = LocalAlloc( LMEM_MOVEABLE, sizeof( DCB ) );
DCBPtr = (DCB *) LocalLock( hCommHandle );
if ( DCBPtr == (DCB *) NULL || hCommHandle == NULL ) {
sprintf( buffer, "TermOpenComm(): Unable to allocate DCB buffer." );
pmsg( buffer );
fileput("DCBPtr = %ld, hCommHandle = %d", DCBPtr, hCommHandle );
CloseComm( nCID );
nCID = NULL;
return( FALSE );
}
ret = GetCommState(nCID, (DCB *) DCBPtr );
if ( ret > 0 ) {
sprintf( buffer, "TermOpenComm(): GetCommState() = %d", ret );
pmsg( buffer );
return( FALSE );
}
DCBPtr->BaudRate = (WORD) baud_rate;
DCBPtr->ByteSize = (BYTE) byte_size;
DCBPtr->Parity = (BYTE) parity;
DCBPtr->StopBits = (BYTE) stop_bits;
DCBPtr->RlsTimeout = 0;
DCBPtr->CtsTimeout = 0;
DCBPtr->DsrTimeout = 0;
DCBPtr->fBinary = TRUE;
DCBPtr->fRtsDisable = FALSE;
DCBPtr->fParity = FALSE;
DCBPtr->fOutxCtsFlow = FALSE;
DCBPtr->fOutxDsrFlow = FALSE;
DCBPtr->fDtrDisable = FALSE;
DCBPtr->fOutX = FALSE;
DCBPtr->fInX = TRUE ;
DCBPtr->PeChar = NULL ;
DCBPtr->fNull = TRUE ;
DCBPtr->fChEvt = FALSE;
DCBPtr->fDtrflow = FALSE;
DCBPtr->fRtsflow = FALSE;
DCBPtr->XonChar = 0x11;
DCBPtr->XoffChar = 0x13;
DCBPtr->XonLim = (WORD) 100 ;
DCBPtr->XoffLim = (WORD) 100 ;
DCBPtr->PeChar = NULL;
DCBPtr->EvtChar = NULL;
DCBPtr->EofChar = 26;
DCBPtr->TxDelay = 0;
ret = SetCommState( (DCB far *) DCBPtr );
if ( ret ) {
sprintf( buffer, "TermOpenComm(): SetCommState() status = %d", ret );
pmsg( buffer );
return( FALSE );
}
return( TRUE );
}